import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { RuleVO } from '../../model/RuleVO';
import { WindowResult } from './WindowResult';


@Component({
  selector: 'app-windowResultQuery',
  templateUrl: './windowResultQuery.component.html',
  styleUrls: ['./windowResultQuery.component.css'],
})

export class WindowResultQueryComponent implements OnInit {

  ruleVOS: RuleVO[] = [];

  selectRule: RuleVO = new RuleVO();

  nzFilterOption = () => true;

  windowResults: WindowResult[] = [];

  constructor(private httpClient: HttpClient) {
  }

  ngOnInit() {
    
  }

  onRuleSerach(): void {
    let url = '/api/v1/stream/rule';
    let body: any = {};    
    this.httpClient.get(url, body).subscribe((data: any) => {
      this.ruleVOS = data;
    });
  }
  
  onSearch(): void {

    this.httpClient    
      .get<WindowResult[]>('/api/v1/stream/windowResult/'+ this.selectRule.id, {})
      .subscribe((results: WindowResult[]) => {
        console.log(results);
        this.windowResults = results;
      });
  }
}
